<template>
  <div>
    <FilterTable
      ref="table"
      columnsRef="partPartOutboundPartSalesReturnMa"
      :columns="columns"
      height="200"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="arr => (this.selectedRows = arr)"
    ></FilterTable>

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" :loading="addBtnState" @click="saveDialog">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { searchSalesPart, isLocked, searchRetreatPart } from '@/api/part/partOut/partSales/index';
import { getUserId } from '@/assets/js/auth';
import { findByEmployeeId } from '@/api/common/auth/employeeAuth/index';
import { getAllUser } from '@/api/customerRepair/afterSaleVisit/resultEntry';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'salesOrder',
  mixins: [dictionary],
  props: ['rowData'],
  data() {
    return {
      columns: this.createTablelist(),
      selectedRows: [],
      addBtnState: null,
      showReturn: false
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    console.log(this.rowData, 'rowData');
    this.searchRetreatPart();
  },
  methods: {
    createTablelist() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库代码',
          dataIndex: 'STORAGE_CODE',
          sorter: true,
          editable: false,
          showOverflowTooltip: true,
          editType: 'select',
          editItems: [],
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        {
          title: '仓库名称',
          dataIndex: 'STORAGE_NAME',
          sorter: true,
          showOverflowTooltip: true
        },
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件数量',
          dataIndex: 'PART_QUANTITY',
          sorter: true,
          filter: true,
          editType: 'number',
          defaultEditable: true,
          editable: true,
          filterType: 'input'
        }
      ];
    },
    async searchRetreatPart() {
      const res = await searchRetreatPart(this.rowData.SALES_PART_NO);
      this.BaseTable.EXECUTE_INSERT(res.data);
    },
    saveDialog() {
      if (this.selectedRows.length > 0) {
        let flag = true;
        this.selectedRows.forEach(x => {
          if (x.PART_QUANTITY >= 0) {
            this.$notify.error({ title: '提示信息', message: '退料数量必须小于0!' });
            flag = false;
          } else if (x.PART_QUANTITY < x.MAX_QUANTITY) {
            this.$notify.error({ title: '提示信息', message: '退料数量不得大于销售数量!' });
            flag = false;
          }
        });
        if (flag) {
          this.selectedRows.forEach(x => {
            x.ITEM_ID = '';
          });
          this.$emit('saveDialog', this.selectedRows);
        }
      } else {
        this.$notify.error({ title: '提示信息', message: '请选择退料信息!' });
      }
    },
    // 点击取消关闭窗口
    closeDialog() {
      this.$emit('close', false);
    }
    // 销售单号查询
  }
};
</script>
<style lang="less" scoped></style>
